<!--
 * @Descripttion: 
 * @Author: liuYaoYu
 * @Date: 2021-12-16 16:45:04
 * @LastEditors: liuYaoYu
 * @LastEditTime: 2021-12-16 16:48:41
-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="text" id="uname"><span>请输入名称</span></input>
    <script>
        var regrex = /^[a-zA-Z0-9-_]{6,16}$/;//六到十六次
        uname.onblur=function(e){
            var span = document.querySelector("span")
            if(regrex.test(e.target.value)){
                span.textContent="正确的"
            }else{
                span.textContent="错误的"
            }
        }
    </script>
</body>
</html>